
# allure生成html报告的目录
allure_dir='allure_report/xml'
allure_report_dir='allure_report/html'
# junit生成的xml报告的目录
junit_dir='output/result.xml'
# case错误后重试次数
rerun=1
# case错误后重试间隔, 单位秒
rerun_delay=0
# case标签，默认boe
marks=boe
# 进程数，默认4
progress=4

# TODO 项目主业务psm和idl仓库路径
#默认IDL
psm="motor.trade.online_sales"
idl=idls/motor/http_idl/trade/trade_online_sales.thrift

## help: Help for this project
help: Makefile
	@echo "Usage:\n  make [command]"
	@echo
	@echo "Available Commands:"
	@sed -n 's/^##//p' $< | column -t -s ':' |  sed -e 's/^/ /'


.PHONY: init
## init: pip3 安装依赖
init:
	@pip3 install git+https://gitlab+deploy-token-5856:nuwSUjJv-zRyb7L_tEQh@code.byted.org/motor_qa/api_test_tool.git -i https://bytedpypi.byted.org/simple
	@pip3 install -r requirements.txt
#	@pip3 install git+https://code.byted.org/EDU-QA/vesta.git@rpc_generator -i https://bytedpypi.byted.org/simple


.PHONY: gen-report
## gen-report: 生成测试报告,会强制覆盖
gen-report:
	@allure generate ${allure_dir} -o ${allure_report_dir} --clean


.PHONY: scan
## scan: 执行测试用例 make run dir=cases/crm rerun=4 rerun_delay=0
scan: init
	@pytest -v cases --collect-only  --parameterized


.PHONY: gen_tcc
## init: pip3 安装依赖
gen_tcc: init clean
	export PATH=$(shell pwd):$(PATH)
	&& python utils/update_file.py


# TODO 不同标签环境的执行命令，执行编写
.PHONY: run
## run: 执行测试用例 例如 make run rerun=2 rerun_delay=1 env='boe' cases='testcase'
run: clean init
	export RUNTIME_ENV=${env} && pytest --dist=loadscope -n=${progress} -sv -m=${env} --alluredir=${allure_dir} --junitxml=${junit_dir} --reruns ${rerun} --reruns-delay ${rerun_delay} ${cases}; make gen-report


.PHONY: run-cron
## run: 执行测试用例 例如 make run-cron rerun=2 rerun_delay=1 env='boe' cases='testcase'
run-cron: clean init
	export RUNTIME_ENV=${env} && pytest --dist=loadscope -n=${progress} -sv -m='${env} and cron' --alluredir=${allure_dir} --junitxml=${junit_dir} --reruns ${rerun} --reruns-delay ${rerun_delay} ${cases}; make gen-report


.PHONY: run-write
## run: 执行测试用例 例如 make run-write rerun=2 rerun_delay=1 env='boe' cases='testcase'
run-write: clean init
	export RUNTIME_ENV=${env} && pytest --dist=loadscope -n=${progress} -sv -m='${env} and write' --alluredir=${allure_dir} --junitxml=${junit_dir} --reruns ${rerun} --reruns-delay ${rerun_delay} ${cases}; make gen-report


.PHONY: run-read
## run: 执行测试用例 例如 make run-read rerun=2 rerun_delay=1 env='boe' cases='testcase'
run-read: clean init
	export RUNTIME_ENV=${env} && python tools/update_tcc.py && pytest --dist=loadscope -n=${progress} -sv -m='${env} and read' --alluredir=${allure_dir} --junitxml=${junit_dir} --reruns ${rerun} --reruns-delay ${rerun_delay} ${cases}; make gen-report


.PHONY: clean
## clean: 清理报告
clean:
	@rm -rf ${allure_dir}/*
	@rm -rf .pytest_cache/
	@rm -rf __pycache__ 
	@rm -rf testcase.json 
	@rm -rf allure_report
	@rm -rf output/*


.PHONY: report
## report: 启动allure报告服务
report:
	@allure serve -h 127.0.0.1 ${allure_dir}


.PHONY: genapi
## genapi: 根据idl生成api模块 genapi 例如：make genapi -psm=motor.trade.online_sales -idl=idls/motor/http_idl/trade/trade_online_sales.thrift
genapi:
	apitest -psm ${psm} -idl ${idl}
